package pers.lws.erp.controller.exception;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import pers.lws.erp.common.emum.MsgStatusEmum;
import pers.lws.erp.common.result.ResultBody;

/**
 * @author liuws
 * @create 2020-07-01 13:48
 */
@RestControllerAdvice
public class MyException {

    @ExceptionHandler(RuntimeException.class)
    public ResultBody handlerExcetion(RuntimeException e) {
        String msg = "";
        //用户名或密码错误
        if (e instanceof UnknownAccountException) {
            msg = MsgStatusEmum.USER_LOGIN_NAME_ERROR.getMsg();
        } else if (e instanceof IncorrectCredentialsException){
            msg = MsgStatusEmum.USER_LOGIN_PASS_ERROR.getMsg();
        } else {
            return ResultBody.customStatus(-999, MsgStatusEmum.SYS_DEFAULT_ERROR.getMsg(), e);
        }
        return ResultBody.error(msg);
    }

}
